package com.example.client.mapper;

import com.example.client.domain.Order;
import com.example.client.domain.Product;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface ProductMapper {

    @Select("select * from product")
    public List<Product> selectProducts();

    @Insert("insert into orderrecord (product_id, username, address, count) VALUES (#{product_id}, #{username}, #{address}, #{count})")
    public void order(Order order);

    @Select("select * from orderrecord where username=#{username} AND product_id=#{product_id}")
    public Order getOrderByProductIdAndUserName(String username, Integer product_id);

    @Update("update orderrecord set count=#{count} where username=#{username} and product_id=#{product_id}")
    public void updateOrderCount(Order order);

    @Select("select * from orderrecord where username=#{username}")
    public List<Order> selectOrderByUserName(String username);
}
